package cn.lijigou.shopping;


import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.math.BigDecimal;
import java.net.HttpURLConnection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Timer;
import java.util.TimerTask;


import cn.lijigou.shopping.domain.Image;
import cn.lijigou.shopping.domain.MResult;
import cn.lijigou.shopping.domain.Order;
import cn.lijigou.shopping.domain.Shop;
import cn.lijigou.shopping.service.MSystem;
import cn.lijigou.shopping.util.Util;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.DialogInterface.OnKeyListener;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Color;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.provider.Browser;
import android.text.Html;
import android.text.SpannableString;
import android.text.Spanned;
import android.text.method.LinkMovementMethod;
import android.text.style.StrikethroughSpan;
import android.util.DisplayMetrics;
import android.util.Log;
import android.util.TypedValue;
import android.view.Gravity;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.Window;
import android.view.View.OnClickListener;
import android.view.View.OnTouchListener;
import android.view.ViewGroup.LayoutParams;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.view.animation.Animation.AnimationListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.RelativeLayout;
import android.widget.ScrollView;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.ViewFlipper;
public class PushDetailShopActivity extends MActivity  implements OnClickListener ,OnTouchListener{
	private String pay_tip = "";
	public  String id = "";
	private long time = 0;
	private String phoneNum="";
	private int cpsState=0;
	private String cid ="";
	private Timer timer;
	private TextView back= null;
	private LinearLayout titleLeftView= null;
	private ViewFlipper viewFlippers;
	private ScrollView scrollViewsOne;
	private Drawable drawableCache;
	private TextView register= null;
	private ProgressDialog mProgress = null;
	public  TextView  text_shop_name = null;
	public  TextView  text_pay_price = null;
	public  TextView  text_shop_size = null;
	public  TextView  text_user_name = null;
	public  TextView  text_shop_address = null;
	public  TextView  text_buyTip= null;
	public  TextView  text_shop_mobile = null;
	public EditText order_name = null;
	public EditText order_address = null;
	public EditText order_mobile = null;
	public EditText order_size = null;
	public TextView payTip = null;
	private TextView phone = null;
	private TextView address;
	private String url1;
	private RelativeLayout rl_phone;
	private RelativeLayout rl_address;
	private LinearLayout layout_goods_detail;
	private View menu_progressBar;
	private ImageView area_imgOne;
	private ProgressBar progressBarOne;
//	private TextView discountOne;
	private TextView economizeOne;
	private TextView end_timeOne;
//	private TextView expire_timeOne;
	private TextView addressOne;
	private TextView infoOne;
	private TextView valueOne;
	public static Button buyOne;
	private TextView buyOne_textview;
	private TextView text_center;
	private TextView discount;
	private Shop shop = new Shop();
	private TextView notice;
	private TextView source;
	
    public Handler waitHander = new Handler(){   
    	public void handleMessage(Message msg) {  
    		if(msg.what==0){
    			
    			if(drawableCache!=null){
    				 
	    				progressBarOne.setVisibility(View.GONE);
	    				area_imgOne.setVisibility(View.VISIBLE);
	    				area_imgOne.setMinimumHeight((int)TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 200, PushDetailShopActivity.this.getResources().getDisplayMetrics()));
	    				area_imgOne.setImageDrawable(drawableCache);
    			}else{
	    				progressBarOne.setVisibility(View.GONE);
	    				area_imgOne.setVisibility(View.VISIBLE);
	    				area_imgOne.setMinimumHeight((int)TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 200, PushDetailShopActivity.this.getResources().getDisplayMetrics()));
	    				area_imgOne.setImageResource(R.drawable.load_big);
    				
    			}
    		}else if(msg.what==8){
    			menu_progressBar.setVisibility(View.VISIBLE);
    		}else if(msg.what==3){
    			getQuot();
    		}else if(msg.what == 1){
    			hideProgress();
    			buyOne.setEnabled(false);
				Toast.makeText(PushDetailShopActivity.this, "网络连接有异常", 1).show();
    		}else if(msg.what == 2){
    			hideProgress();
    			buyOne.setEnabled(true);
    			if(shop != null){
    				setData(shop);
    			}
    			
    		}
 
    	}   
    };   
	
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.shop_detail);
		overridePendingTransition(R.anim.push_in,R.anim.push_out);
		initDate();
		ShopDetailActivity.mList.add(this);
	}
	private void initDate() {
		// TODO Auto-generated method stub
		setViews();
		setOnClickListeners();
		Intent intent = getIntent();   
		String id = intent.getStringExtra("shopid");
		getShop(id);
//		setData(shop);
		DisplayMetrics dm= new DisplayMetrics();
		getWindowManager().getDefaultDisplay().getMetrics(dm);
	}
	
	private void getShop(final String id) {
		new Thread() {
			public void run() {
				if(getNetConnectState(PushDetailShopActivity.this)){
					showProgress();
					MResult mResult = null;
						mResult = MSystem.getShopDetail(shop,id);
					if(mResult !=null){
						Boolean b = mResult.isSuccess();
						Log.i("Boolean", b+"");
						if(b){
							
							waitHander.sendEmptyMessage(2);
						}
					}else{
						waitHander.sendEmptyMessage(1);
					}
				}else{
					waitHander.sendEmptyMessage(1);
				}
			}
		}.start();
		
	}
	
	private void  setViews(){
		viewFlippers = (ViewFlipper) this.findViewById(R.id.viewFlippers);
		viewFlippers.setVisibility(View.VISIBLE);
		this.findViewById(R.id.viewpagerLayout).setVisibility(View.GONE);
		viewFlippers.addView(LayoutInflater.from(this).inflate(R.layout.scrollviews, null));
//		scrollViewsOne = (ScrollView) viewFlippers.findViewById(R.id.scrollViewOne);
		back = (TextView) this.findViewById(R.id.title_btn_left);
		titleLeftView = (LinearLayout) this.findViewById(R.id.titleLeftView);
		back.setBackgroundResource(R.drawable.title_back_normal);

		register = (TextView) this.findViewById(R.id.title_btn_right);
		this.findViewById(R.id.titleRightView).setVisibility(View.GONE);
		register.setVisibility(View.GONE);
		phone = (TextView) this.findViewById(R.id.phone);
		menu_progressBar = (View) this.findViewById(R.id.menu_progressBar);
		menu_progressBar.setVisibility(View.GONE);
		
		//scrollViewsOne的组件
		buyOne = (Button) viewFlippers.findViewById(R.id.buy);
		buyOne_textview = (TextView) viewFlippers.findViewById(R.id.textview_buy);
		area_imgOne = (ImageView) viewFlippers.findViewById(R.id.area_img);
		progressBarOne = (ProgressBar) viewFlippers.findViewById(R.id.progressBar);
//		discountOne = (TextView) viewFlippers.findViewById(R.id.discount);
		economizeOne = (TextView) viewFlippers.findViewById(R.id.economize);
		end_timeOne = (TextView) viewFlippers.findViewById(R.id.end_time);
//		expire_timeOne = (TextView) viewFlippers.findViewById(R.id.expire_time);
		addressOne = (TextView)viewFlippers. findViewById(R.id.address);
		infoOne = (TextView) viewFlippers.findViewById(R.id.info);
		valueOne = (TextView) viewFlippers.findViewById(R.id.value);
		
		
		text_center=(TextView) this.findViewById(R.id.text_center);
		discount = (TextView) this.findViewById(R.id.discount);
		notice = (TextView) this.findViewById(R.id.notice);
		source = (TextView) this.findViewById(R.id.source);
		
	    rl_phone = (RelativeLayout) this.findViewById(R.id.rl_phone);
	    rl_address = (RelativeLayout) this.findViewById(R.id.rl_address);
	    layout_goods_detail = (LinearLayout) this.findViewById(R.id.layout_goods_detail);
	    address = (TextView)this. findViewById(R.id.address);
		
		
	}
	
	String getIdToString(int id){
		String string=this.getResources().getString(id);
		return string;
	}
	
	 
	private void  setOnClickListeners(){
		buyOne.setOnClickListener(this);
		buyOne.setOnTouchListener(this);
		titleLeftView.setOnClickListener(this);
		rl_phone.setOnClickListener(this);
		rl_address.setOnClickListener(this);
		layout_goods_detail.setOnClickListener(this);
	}

	public void onClick(View v) {
		MSystem.pv += 1;
		switch (v.getId()) {
		case R.id.rl_phone:
			call();
			break;
		case R.id.rl_address:
			map();
			break;
		case R.id.layout_goods_detail:
			url1 = shop.getDetail();
			if (isNull(url1)) {
				Intent intent1 = new Intent(PushDetailShopActivity.this, GoogsDetailActivity.class);
				intent1.putExtra("url", url1);
				this.startActivity(intent1);
			} else {
				Toast.makeText(this, "抱歉，本团购暂时还没有详情!", 1).show();
			}

			break;
 
		//买的效果实现
		case R.id.buy:
			buyOne.setEnabled(false);
			MSystem.buy += 1;
			if (cpsState > 0) {
				boolean isCps = MSystem.isCps(cid).isSuccess();
				if (isCps) {
						Intent intent_order = new Intent(PushDetailShopActivity.this, OrderApprobateActivity.class);
						shop.setDrawable(null);
						intent_order.putExtra("shop", shop);
						PushDetailShopActivity.this.startActivity(intent_order);
				} else {
					buyOne.setEnabled(true);
					Toast.makeText(this, R.string.sorry_tips3, 1).show();
				}
			} else {
				Integer hour = Util.getCurSysTime();
				int start = shop.getBuy_start_time();
				int end = shop.getBuy_end_time();
				if(hour >= start && hour < end){
					//支付
						Intent intent_order = new Intent(PushDetailShopActivity.this, OrderApprobateActivity.class);
						shop.setDrawable(null);
						intent_order.putExtra("shop", shop);
						PushDetailShopActivity.this.startActivity(intent_order);
				} else {
					// 如果超时 提示用户此时段订单将在第二天处理
					new AlertDialog.Builder(PushDetailShopActivity.this)
					.setIcon(R.drawable.icon).setTitle("是否继续购买？")
					.setMessage(shop.getBuy_end_time() + ":00-" + shop.getBuy_start_time() + ":00间的订单，我们将在第二天工作时间帮您处理")
					.setPositiveButton(
							R.string.alert_dialog_ok, new DialogInterface.OnClickListener() {
								public void onClick(DialogInterface dialog, int whichButton) {
									// 支付
										Intent intent_order = new Intent(PushDetailShopActivity.this, OrderApprobateActivity.class);
										shop.setDrawable(null);
										intent_order.putExtra("shop", shop);
										PushDetailShopActivity.this.startActivity(intent_order);
								}
							})
					.setNegativeButton(R.string.alert_dialog_cancel, new DialogInterface.OnClickListener() {
						public void onClick(DialogInterface dialog, int whichButton) {
							buyOne.setEnabled(true);
							dialog.dismiss();
						}
					})
					.setOnKeyListener(new OnKeyListener() {
						
						public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {
							// TODO Auto-generated method stub
							if (keyCode == KeyEvent.KEYCODE_BACK) {
								buyOne.setEnabled(true);
								return false;
							}
							return false;
						}
					})
					.create().show();

				}
				
				
				}
			break;
 
			case R.id.titleLeftView:
				if (ShopDetailActivity.mList.contains(this)) {
					ShopDetailActivity.mList.remove(this);
				}
				
				if(HomeActivity.parentMainTab!=null){
					Animation animation=AnimationUtils.loadAnimation(PushDetailShopActivity.this,R.anim.home_push_rightout);
					HomeActivity.parentMainTab.mHost.getCurrentView().startAnimation(animation);
					HomeActivity.parentMainTab.mHost.setCurrentTab(0);	
					HomeActivity.parentMainTab.main_tab_home.setChecked(true);
				    Animation animations=AnimationUtils.loadAnimation(PushDetailShopActivity.this,R.anim.home_push_rightin);
				    HomeActivity.parentMainTab.mHost.getCurrentView().startAnimation(animations);
				}else{
					
					Intent mIntent  = new Intent(PushDetailShopActivity.this,MainTabActivity.class);
				    startActivity(mIntent);
				    PushDetailShopActivity.this.finish();
					
				}
				this.finish();
				break;
		}
	}
	
	
	public boolean onTouch(View v, MotionEvent event) {
		// TODO Auto-generated method stub

		switch (event.getAction()) {
		case MotionEvent.ACTION_DOWN:
			if(v.getId() == buyOne.getId()){
				buyOne.setTextColor(Color.WHITE);
				buyOne.setBackgroundResource(R.drawable.buy_btn_pressed);
			}
			
			break;
		case MotionEvent.ACTION_UP:
			if(v.getId() == buyOne.getId()){
				buyOne.setTextColor(Color.BLACK);
				buyOne.setBackgroundResource(R.drawable.buy_btn_normal);
			}
			break;

		default:
			break;
		}

		return false;
	}
	
	public void map() {
		if( !isNull(shop.getLat()) || shop.equals("0")){
			Toast.makeText(this, "该商户不支持地图服务", 1).show();
		}else{
			if(MSystem.mLocation==null){
				Toast.makeText(this, "尚未知道你的坐标", 1).show();
			}else{
				Intent intent = new Intent(this, MapRoutePlanActivity.class);
				intent.putExtra("city", MSystem.mLocation.city);
				intent.putExtra("start_lat", MSystem.mLocation.getLat());
				intent.putExtra("start_lng", MSystem.mLocation.getLng());
				intent.putExtra("end_lat", Double.parseDouble(shop.getLat()));
				intent.putExtra("end_lng", Double.parseDouble(shop.getLng()));
				this.startActivity(intent);
			}
		}
	}
	
	public void call() {
		if(!"".equals(phoneNum)&&phoneNum!=null){
			Uri uri = Uri.parse("tel:"+phoneNum);
		    Intent intent = new Intent(Intent.ACTION_VIEW, uri);
		    intent.putExtra(Browser.EXTRA_APPLICATION_ID, this.getPackageName());
		    this.startActivity(intent);
		}else{
			Toast.makeText(this, R.string.not_phone_number, 1).show();
		}
	}

	
	
	public void setData(final Shop shop){
		  if(timer!=null){timer.cancel();}
//		  String shop_title = shop.getShop_title();
		  String strValue = shop.getValue();
		  String strPrice = shop.getPrice();
		  String strEnd_time = shop.getEnd_time();
		  String strDiscount = shop.getDiscount();
		  String strDistance = shop.getDistance();
		  String strInfo = shop.getShop_title()+shop.getInfo();
		  String[] strDesc = strInfo.split("温馨提示：");
		  String StrUse_num = shop.getUse_num();
		  
		  
		  String strShop_address = shop.getShop_address();
		  String strShop_tel = shop.getShop_tel();
		  String strExpireTime = shop.getExpireTime();
		  String strSource = shop.getSource();
		  cpsState = shop.getCpsState();
		  cid = shop.getId();
		  phoneNum  = strShop_tel;
		  
		  final String photo_large = shop.getPhoto_large();
		  
			if(isNull(photo_large)){
//						asyncImageLoader = new AsyncImageLoader(this);
						String imageUrl = photo_large;
						String id = shop.getId();
			    		progressBarOne.setVisibility(View.GONE);
			    		area_imgOne.setVisibility(View.VISIBLE);
	    				area_imgOne.setMinimumHeight((int)TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 200, PushDetailShopActivity.this.getResources().getDisplayMetrics()));

			    		if(drawableCache!=null){
			    			area_imgOne.setImageDrawable(drawableCache);
			    		}else{
			    			sirectLoadImageFromUrl(imageUrl);	
			    		}
						
			}
			if(shop != null){
				  if(text_center!=null){
						text_center.setText("团购详情(1/1)");
				  }
			  }
			if(isNull(strDesc[0])){
				infoOne.setText(strDesc[0]);
			}
			if(strDesc.length>1){
				if(isNull(strDesc[1])){
					  notice.setText(strDesc[1]);
				  }
			}else{
				findViewById(R.id.layout_notice).setVisibility(View.GONE);
			}
		  
		  if(isNull(phoneNum)){
			  phone.setText(phoneNum);
		  }else{
			  rl_phone.setVisibility(View.GONE);
		  }
		  
		  if(isNull(strShop_address)){
			  address.setText(strShop_address);
	  }else{
		  rl_address.setVisibility(View.GONE);
	  }
		  if(isNull(strInfo)){
				  infoOne.setText(strInfo);
		  }
		  if(isNull(strExpireTime)){
//				  expire_timeOne.setText(strExpireTime);
		  }
		  
		  if(isNull(strSource)){
			  source.setText("【"+shop.getSource()+"】"
					  +"仅售"+new BigDecimal(Double.parseDouble(strPrice)).setScale(1,java.math.BigDecimal.ROUND_HALF_UP)+"元！");
		  }
		  if(isNull(strShop_address)){
				  addressOne.setText(strShop_address);
		  }
		  if(isNull(strDiscount)){
			  discount.setText(strDiscount+getIdToString(R.string.fold));
		  }else{
			  discount.setText(getIdToString(R.string.No_discount));
		  }
		  if(isNull(strValue)&&!strValue.equals(getIdToString(R.string.No_))){
			  String str=getIdToString(R.string.original)+strValue+getIdToString(R.string.yuan);
			  valueOne.setText(str);
		  }else{
			  valueOne.setText(R.string.no_original_price);
		  }
		  if(isNull(strValue)&&isNull(strPrice)&&!strValue.equals(getIdToString(R.string.No_))&&!strPrice.equals(getIdToString(R.string.No_))){
			  Double mSavePrice = Double.parseDouble(strValue)-Double.parseDouble(strPrice);
			  BigDecimal b = new BigDecimal(mSavePrice);  
			  double f1 = b.setScale(1,BigDecimal.ROUND_HALF_UP).doubleValue(); 
			  economizeOne.setText(f1+getIdToString(R.string.yuan));
	    }else{
	    	  economizeOne.setText(R.string.no_save);
		  }
		  if(isNull(strEnd_time)){
			  long time = Long.parseLong(strEnd_time);
			  if(time>0){
				  setExpireTime(time);
			  }else{
					  end_timeOne.setText(R.string.has_expired);
			  }
		  }else{
				  end_timeOne.setText(R.string.No_);
			  }
		  if(isNull(strPrice)&&!strPrice.equals(getIdToString(R.string.No_))){
				  buyOne_textview.setText("￥"+new BigDecimal(Double.parseDouble(strPrice)).setScale(1,java.math.BigDecimal.ROUND_HALF_UP)+"元");
			  }else{
					  buyOne_textview.setText(R.string.No_);
				  }
		  if(!"1".equals(shop.getIs_buy())){
		  }
	}
	/**
	 * 剩余时间定时器
	 */
	public void setExpireTime(long t){
		  time = t;
		  TimerTask task = new TimerTask() { 
				 public void run() { 
					 time--;
					 waitHander.sendEmptyMessage(3);
				} 
			}; 
		 timer = new Timer(); 
		 timer.schedule(task, 0,1000);	
	 }
	/**
	 * 计算剩余时间
	 */
	 public void getQuot(){
		  long dd = 0;
		  long hh = 0;
		  long mm = 0;
		  long ss = 0;
		   dd = time / (60*60*24);
		   hh = time % (60*60*24) / (60*60);
		   mm = time % (60*60*24) % (60*60) / 60;
		   ss = time % (60*60*24) % (60*60) % 60;
		   String strTime = dd+"天"+hh+"时"+mm+"分"+ss+"秒";
		   end_timeOne.setText(strTime); 
	 }
		 /**
		  * 判断是否为空
		  */
		public Boolean isNull(String str){
			if(str!=null&&!str.equals("")&&str!=""&&!str.equals("null")){
				return true;
			}
			return false;
		}
		public boolean onKeyDown(int keyCode, KeyEvent event) {
			if (keyCode == KeyEvent.KEYCODE_BACK) {
				if(ShopDetailActivity.mList.contains(this)){
					ShopDetailActivity.mList.remove(this);
				}
				if(HomeActivity.parentMainTab!=null){
					Animation animation=AnimationUtils.loadAnimation(PushDetailShopActivity.this,R.anim.home_push_rightout);
					HomeActivity.parentMainTab.mHost.getCurrentView().startAnimation(animation);
					HomeActivity.parentMainTab.mHost.setCurrentTab(0);	
					HomeActivity.parentMainTab.main_tab_home.setChecked(true);
				    Animation animations=AnimationUtils.loadAnimation(PushDetailShopActivity.this,R.anim.home_push_rightin);
				    HomeActivity.parentMainTab.mHost.getCurrentView().startAnimation(animations);
				}else{
					
					Intent mIntent  = new Intent(PushDetailShopActivity.this,MainTabActivity.class);
				    startActivity(mIntent);
				    PushDetailShopActivity.this.finish();
					
				}
				this.finish();
				return true;
			}

			return false;
		}
		static class AlixOnCancelListener implements
				DialogInterface.OnCancelListener {
			Activity mcontext;
		
			AlixOnCancelListener(Activity context) {
				mcontext = context;
			}
		
			public void onCancel(DialogInterface dialog) {
				mcontext.onKeyDown(KeyEvent.KEYCODE_BACK, null);
			}
		}
		
	     //直接加载图片
	 public  void sirectLoadImageFromUrl(final String url) {
		 	String filePath;
		    filePath="/sdcard/tuangou/"+shop.getId()+"large.jpg";
	 		File file=new File(filePath);
			if(file.exists()){
				
				Drawable drawable=Drawable.createFromPath(filePath);
				if(drawable!=null){
					drawableCache=drawable;
					waitHander.sendEmptyMessage(0); 
				}else{
					file.delete();
				}
			}else {
	    	 
			new Thread() {
				InputStream is = null;
				Drawable drawable = null;
				
				public void run() {
					// TODO Auto-generated method stub
					try {
						HttpURLConnection conn = Util.getHttpURLConnection(url);
						conn.setDoInput(true);
						if (conn.getResponseCode() == 200) {
							is = conn.getInputStream();
							int contentLength=conn.getContentLength();
							
							if (is != null) {
								Bitmap bitmap = BitmapFactory.decodeStream(is);
								drawable = new BitmapDrawable(bitmap);
								if(drawable!=null&&contentLength>4){
									drawableCache=drawable;
									waitHander.sendEmptyMessage(0);
									try{
										String filePath ;
										filePath = "/sdcard/tuangou/"+shop.getId()+"large.jpg";
			   							File fp = new File("/sdcard/tuangou");
			   							File file = new File("/sdcard/tuangou/.nomedia");
			   							if (!fp.exists()) {
			   								fp.mkdir();
			   								if((!file.exists())){  
			   									file.createNewFile();
			   								}
			   							}else{
			   								File f = new File(filePath);
			   								f.createNewFile();
			   								FileOutputStream fos = new FileOutputStream(f);
			   								bitmap.compress(Bitmap.CompressFormat.JPEG, 100, fos);
			   								fos.flush();
			   								fos.close();
//			   								imageFileSave.imageSave(imageService,new Image(id, filePath));
			   							}
									}catch (Exception e) {
										e.printStackTrace();
									}
									
									try{
										String filePath ;
										filePath = "/sdcard/tuangou/"+shop.getId()+"large.jpg";
			   							File fp = new File("/sdcard/tuangou");
			   							File file = new File("/sdcard/tuangou/.nomedia");
			   							if (!fp.exists()) {
			   								fp.mkdir();
			   								if((!file.exists())){  
			   									file.createNewFile();
			   								}
			   							}else{
			   								File f = new File(filePath);
			   								f.createNewFile();
			   								FileOutputStream fos = new FileOutputStream(f);
			   								bitmap.compress(Bitmap.CompressFormat.JPEG, 100, fos);
			   								fos.flush();
			   								fos.close();
//			   								imageFileSave.imageSave(imageService,new Image(id, filePath));
			   							}
									}catch (Exception e) {
										e.printStackTrace();
									}
								}
							}
						}
					} 
				catch (Exception e) {
					e.printStackTrace();
						}
					}
						}.start();
			}
	}
	 	public boolean getNetConnectState(Context context) {
			boolean netConnect = false;
			ConnectivityManager connMgr = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
			NetworkInfo info = connMgr.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
			NetworkInfo infoM = connMgr.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
			if (info.isConnected() || infoM.isConnected()) {
				netConnect = true;
			}
			return netConnect;
		}
	 	
	 	/**
		 * 显示等待框
		 */
		protected void showProgress() {
			this.runOnUiThread(new Runnable() {
				public void run() {	
					mProgress = new ProgressDialog(PushDetailShopActivity.this);
					mProgress.requestWindowFeature(Window.FEATURE_NO_TITLE);
					mProgress.setMessage(PushDetailShopActivity.this.getResources().getString(R.string.loading_please_wait));
					mProgress.setCancelable(false);
					mProgress.show();
				}
			});
		}

		/**
		 * 取消等待框
		 */
		protected void hideProgress() {
			
			this.runOnUiThread(new Runnable() {
				public void run() {
					if (mProgress != null) {
						mProgress.dismiss();
					}
				}
			});
		}
		
}
